/**
 *
 */
package co.fitstart.api.web.controller.content;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo2do.core.support.Page;
import com.demo2do.core.support.Result;
import com.demo2do.core.utils.JsonUtils;

import co.fitstart.api.service.ContentService;
import co.fitstart.entity.content.Activity;

/**
 * @author downpour
 *
 */
@Controller
@RequestMapping("/v1/activities")
public class ActivityApiController {

    @Autowired
    private ContentService contentService;

    /**
     * List activity
     *
     * @param keyword
     * @param page
     * @return
     */
    @RequestMapping("")
    public @ResponseBody String list(@RequestParam(value = "q", required = false) String keyword, Page page) {

        Result result = new Result();

        List<Activity> activities = contentService.listActivity(keyword, page);

        result.success().data("page", page)
                        .data("activities", activities);
        if(StringUtils.isNoneBlank(keyword)) {
            result.data("q", keyword);
        }
        return JsonUtils.toJsonString(result);
    }

}
